﻿using System;

namespace PageAdmin.Utils.ORM
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    /// <summary>
    /// 子数据特性
    /// </summary>
    public class SubdataAttribute : Attribute
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="foreignKey">外键</param>
        /// <param name="syncDelete">同步删除，默认true</param>
        /// <param name="listSyncLoad">列表同步加载</param>
        /// <param name="detailSyncLoad">详情页同步加载</param>
        /// <param name="syncAdd">同步添加</param>
        /// <param name="syncEdit">同步编辑</param>
        /// <param name="sqlCondition">查询条件</param>
        /// <param name="orderBy">排序方式</param>
        public SubdataAttribute(string foreignKey, bool syncDelete = true, bool listSyncLoad = false, bool detailSyncLoad = false,bool syncAdd =false,bool syncEdit=false,string sqlCondition = null,string orderBy=null)
        {
            this.ForeignKey = foreignKey;
            this.SyncAdd = syncAdd;
            this.SyncDelete = syncDelete;
            this.SyncEdit = syncEdit;
            this.ListSyncLoad = listSyncLoad;
            this.DetailSyncLoad = detailSyncLoad;
            this.SqlCondition = sqlCondition;
            this.OrderBy = orderBy;
        }
        /// <summary>
        /// 外键名称
        /// </summary>
        public string ForeignKey { get; set; }

        /// <summary>
        /// 是否同步添加子数据
        /// </summary>
        public bool SyncAdd { get; set; }

        /// <summary>
        /// 是否自动删除子数据
        /// </summary>
        public bool SyncDelete { get; set; }

        /// <summary>
        /// 是否同步编辑子数据
        /// </summary>
        public bool SyncEdit { get; set; }

        /// <summary>
        /// 详情数据是否同步加载
        /// </summary>
        public bool DetailSyncLoad { get; set; }

        /// <summary>
        /// 列表数据是否Sync加载
        /// </summary>
        public bool ListSyncLoad { get; set; }

        /// <summary>
        /// 读取条件
        /// </summary>
        public string SqlCondition { get; set; }

        /// <summary>
        /// 排序方式
        /// </summary>
        public string OrderBy { get; set; }
    }
}
